package cfs.model;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;

import org.mybeans.dao.GenericDAO;
import org.mybeans.factory.BeanTable;

public class Model {

	private CustomerDAO customerDao;
	private EmployerDAO employeeDao;
	private FundDAO fundDao;
	private FundPriceHistoryDAO fundHistoryDao;
	private PositionDAO positionDao;
	private TransactionDAO transactionDao;

	public Model(ServletConfig config) throws ServletException {

		String jdbcDriver = config.getInitParameter("jdbcDriverName");
		String jdbcURL = config.getInitParameter("jdbcURL");
		BeanTable.useJDBC(jdbcDriver, jdbcURL);

		customerDao = new CustomerDAO();
		employeeDao = new EmployerDAO();
		fundDao = new FundDAO();
		transactionDao = new TransactionDAO(new GenericDAO<?>[] { customerDao });

		positionDao = new PositionDAO(new GenericDAO<?>[] { customerDao,
				fundDao });
		fundHistoryDao = new FundPriceHistoryDAO(
				new GenericDAO<?>[] { fundDao });

	}

	public PositionDAO getPositionDao() {
		return positionDao;
	}

	public TransactionDAO getTransactionDao() {
		return transactionDao;
	}

	public CustomerDAO getCustomerDao() {
		return customerDao;
	}

	public EmployerDAO getEmployerDao() {
		return employeeDao;
	}

	public FundDAO getFundDao() {
		return fundDao;
	}

	public FundPriceHistoryDAO getFundHistoryDao() {
		return fundHistoryDao;
	}
}
